﻿@using Apps.Web.Core;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "样例程序";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    string info = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
    List<permModel> perm = null;
}
<link href="~/Scripts/fancybox/jquery.fancybox-1.3.4.css" rel="stylesheet" />
<script src="~/Scripts/fancybox/jquery.fancybox.min.js"></script>
<script src="~/Scripts/jquery.jqprint-0.3.js"></script>
<div class="mvctool">
    <input id="txtQuery" placeholder="请输入关键字" type="text" class="searchText" />
    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query,ref perm, "Query", true)
    @Html.ToolButton("btnCreate", "fa fa-plus", Resource.Create, ref perm, "Create", true)
    @Html.ToolButton("btnEdit", "fa fa-pencil", Resource.Edit, ref perm, "Edit", true)
    @Html.ToolButton("btnDetails", "fa fa-list", Resource.Details, ref perm, "Details", true)
    @Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete, ref perm, "Delete", false)
    @Html.ToolButton("btnPrint", "fa fa-print", "打印表格", true)
</div>
<table id="List"></table>

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")
<script type="text/javascript">
    $(function () {
        $('#List').datagrid({
            url: '/SysSample/GetList',
            width: SetGridWidthSub(10),
            methord: 'post',
            height: SetGridHeightSub(37),
            fitColumns: true,
            sortName: 'Id',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 10,
            pageList: [10, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            onLoadSuccess: function (data) {
                 @foreach(var r in perm){if(r.Category==2){@Html.Raw("$(this).datagrid('hideColumn','"+r.KeyCode+"');");}}//动态根据权限隐藏列
            },
            columns: [[
                { field: 'Id', title: 'ID', width: 80,sortable: true },
                { field: 'Name', title: '名称', width: 60 },
                { field: 'Age', title: '年龄', width: 50, align: 'right', sortable: true },
                { field: 'Bir', title: '生日', width: 80, align: 'right', sortable: true, formatter: function (value) { return SubStrYMD(value) } },
                {
                    field: 'Photo', title: '照片', width: 100, align: 'center', formatter: function (value, row, index) {
                        return '<a class="example" title="'+row.Note+'" href="' + value + '"><img width="80px" alt="example" src="' + value + '" /></a>';
                    }
                },
                { field: 'Note', title: '备注', width: 260 },
                { field: 'CreateTime', title: '@Resource.TitleCreateTime', width: 160, align: 'center' }
            ]]
        });
    });
    //导出
    function ExportData(par) {
        window.location = "/SysSample/Reporting" + par;
    }
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnExport").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/SysHelper/ReportControl'></iframe>");
            $("#modalwindow").window({ title: '@Resource.Export', width: 320, height: 200, iconCls: 'fa fa-plus' }).window('open');
        });
        $("#btnCreate").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='../@info/SysSample/Create'></iframe>");
            $("#modalwindow").window({ title: Lang.Create, width: 500, height: 455, iconCls: 'fa fa-plus' }).window('open');
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='100%'  frameborder='0' src='/SysSample/Edit?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Edit', width: 700, height: 455, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });
        $("#btnDetails").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0' src='/SysSample/Details?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Details', width: 500, height: 300, iconCls: 'fa fa-list' }).window('open');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
	        });
        $("#btnQuery").click(function () {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#List").datagrid("load", { queryStr: queryStr});
        });
        $("#btnQueryAll").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/SysHelper/Query'></iframe>");
            $("#modalwindow").window({ title: Lang.Create, width: 700, height: 400, iconCls: 'fa fa-plus' }).window('open');
        });
        $("#btnDelete").click(function () {
            dataDelete("@Url.Action("Delete")", "List");
        });
        $("#btnPrint").click(function () {
            var tablestr = CreateFormPage("datagrid", $("#List"));
            $("#modalwindow").html(tablestr);
            $("#modalwindow").window({ title: "打印", width: 1000, height: 600, iconCls: 'fa fa-plus' }).window('open');
        });
    });
</script>
